home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 43.zip / ANC 15.adf / demo / pi.c < prev    next >
C/C++ Source or Header  |  1987-01-01  |  772b  |  45 lines

  1. /* Program pi.c originally distributed by Microsoft to demonstrate Codeview */
  2. /* for IBM PCs and compatibles.  Released by Microsoft into the public domain. */
  3. #include <time.h>
  4. #define    MAXPRC    4000
  5.  
  6. char p[MAXPRC];
  7. char t[MAXPRC];
  8. int q;
  9.  
  10. main(argc,argv)
  11. int argc;
  12. char *argv[];
  13. {
  14.     long startime, endtime;
  15.     register int i;
  16.  
  17.     if (argc == 2) {
  18.         sscanf(argv[1],"%d",&q);
  19.     } else {
  20.         printf("Usage: pi [precision]\n");
  21.         exit(-1);
  22.     }
  23.  
  24.     if (q > MAXPRC)    {
  25.         printf("Precision too large\n");
  26.         exit(-1);
  27.     }
  28.  
  29.     /* compute pi */
  30.  
  31.     time(&startime);
  32.     arctan(2);
  33.     arctan(3);
  34.     mul4();
  35.     time(&endtime);
  36.  
  37.     /* print pi */
  38.  
  39.     printf("pi = %d.",p[0]);
  40.     for (i = 1; i <= q; i++)
  41.         printf("%d",p[i]);
  42.     printf("\n");
  43.     printf("%ld seconds to compute %d digits of pi\n",endtime - startime,q);
  44. }
  45.